package com.glory.huaweipda.model

import com.glory.huaweipda.base.Constant
import com.glory.huaweipda.bean.*
import com.google.gson.JsonObject
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_VersionEntity
import rxhttp.toClass
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class TaskRepository : BaseRepository() {

    val url = "http://" + Constant.mainUrl + "/PDA/"
    val mConnectTimeout = Constant.connectTimeout

    /**
     * 获取批次信息
     */
    suspend fun defaultLotInfo(map: JsonObject): LotInfoBean {
        return RxHttp.postForm(url + "View_Mes_Lot_Info")
            .addAll(getInJsonData(map, "LotInfo"))
            .connectTimeout(mConnectTimeout)
            .toResponse<LotInfoBean>()
            .await()
    }

    /**
     * 获取批次实时日志
     */
    suspend fun defaultGetEQPLog(map: JsonObject): EqpLogBean {
        return RxHttp.postForm(url + "Message_Mes_GetEQPLog")
            .addAll(getInJsonData(map, "GetEQPLog"))
            .connectTimeout(mConnectTimeout)
            .toResponse<EqpLogBean>()
            .await()
    }

    /**
     * 批次进站
     * */

    suspend fun defaultTrackIn(map: JsonObject): Any {
        return RxHttp.postForm(url + "Tran_Lot_TrackIn")
            .addAll(getInJsonData(map, "TrackIn"))
            .connectTimeout(mConnectTimeout)
            .toResponse<Any>()
            .await()
    }

    /**
     * 批次出站
     * */

    suspend fun defaultTrackOut(map: JsonObject): Any {
        return RxHttp.postForm(url + "Tran_Lot_TrackOut")
            .addAll(getInJsonData(map,"TrackOut"))
            .connectTimeout(mConnectTimeout)
            .toResponse<Any>()
            .await()
    }

    /**
     * 重新测试
     * */

    suspend fun defaultCancelTrackIn(map: JsonObject): Any {
        return RxHttp.postForm(url + "Tran_CancelTrackIn")
            .addAll(getInJsonData(map, "CancelTrackIn"))
            .connectTimeout(mConnectTimeout)
            .toResponse<Any>()
            .await()
    }

    /**
     * 设备日志
     * */

    suspend fun defaultdefaultGetEQPLotInfo(map: JsonObject): EQPLotInfoBean {
        return RxHttp.postForm(url + "View_Mes_GetEQPLotInfo")
            .addAll(getInJsonData(map, "GetEQPLotInfo"))
            .connectTimeout(mConnectTimeout)
            .toResponse<EQPLotInfoBean>()
            .await()
    }

    /**
     * 获取区域地址
     * */

    suspend fun defaultGetAreaList(): ArrayList<String> {
        return RxHttp.postForm(url + "View_Mes_GetAreaList")
            .addAll(getInJsonData(JsonObject(), "GetAreaList"))
            .connectTimeout(mConnectTimeout)
            .toResponse<ArrayList<String>>()
            .await()
    }

    /**
     * 设备看板
     * */

    suspend fun defaultGetAreaEqpInfo(map: JsonObject): ArrayList<AreaEqpInfoBean> {
        return RxHttp.postForm(url + "View_Mes_GetAreaEqpInfo")
            .addAll(getInJsonData(map, "GetAreaEqpInfo"))
            .connectTimeout(mConnectTimeout)
            .toResponse<ArrayList<AreaEqpInfoBean>>()
            .await()
    }

    /**
     * 设备状态转换
     */
    suspend fun defaultEqpStateChangeInfo(map: JsonObject): Any {
        return RxHttp.postForm(url + "Tran_EqpState_Change")
            .addAll(getInJsonData(map, "EqpStateChange"))
            .toResponse<Any>()
            .await()
    }

    /**
     * 获取APP更新地址
     * */

    suspend fun defaultUpdate(map: Map<String, String>): FreeUI_VersionEntity {
        return RxHttp.get(Constant.REQUEST_URL_DEBUG)
            .addAll(map)
            .toClass<FreeUI_VersionEntity>()
            .await()
    }

}